package com.base.cn.platform.os.controller.web.course.favorites;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.service.course.favorites.CourseFavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;

/**
 * 课程收藏
 *
 * @author s.li
 * @date 2018/10/24
 */
@Controller
public class WebCourseFavoritesController extends WebBaseController {

    @Autowired
    private CourseFavoritesService courseFavoritesService;

    /**
     * 添加用户收藏
     * @param request
     * @param courseId 课程ID
     * @return Map<String,Object>
     */
    @RequestMapping("/web/uc/course/saveCourseFavorites")
    @ResponseBody
    public Map<String,Object> saveCourseFavorites(HttpServletRequest request,
                                                  @RequestParam("courseId") BigDecimal courseId){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        return courseFavoritesService.saveCourseFavorites(userId,courseId);
    }

    /**
     * 获取用户的单个课程收藏记录
     * @param request HttpServletRequest
     * @param courseId 课程ID
     * @return Map<String,Object>
     */
    @RequestMapping("/web/course/findUserCourseFavorites")
    public Map<String,Object> findUserCourseFavorites(HttpServletRequest request,
                                                      @RequestParam("courseId") BigDecimal courseId){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String,Object> courseFavorites = courseFavoritesService.findUserCourseFavorites(userId,courseId);
        return ResultUtil.SUCCESS(courseFavorites);
    }
}
